package com.ruoyi.mobile.service.impl;

import java.util.List;

import cn.hutool.core.util.StrUtil;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.mobile.model.vo.LessonVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.mobile.mapper.LessonMapper;
import com.ruoyi.mobile.domain.Lesson;
import com.ruoyi.mobile.service.ILessonService;

/**
 * 课程视频Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-09-26
 */
@Service
public class LessonServiceImpl implements ILessonService 
{
    @Autowired
    private LessonMapper lessonMapper;

    /**
     * 查询课程视频
     * 
     * @param id 课程视频主键
     * @return 课程视频
     */
    @Override
    public Lesson selectLessonById(Integer id)
    {
        return lessonMapper.selectLessonById(id);
    }

    @Override
    public List<LessonVo> getAllLesson() {
        return lessonMapper.getAllLesson();
    }

    /**
     * 查询课程视频列表
     * 
     * @param lesson 课程视频
     * @return 课程视频
     */
    @Override
    public List<Lesson> selectLessonList(Lesson lesson)
    {
        return lessonMapper.selectLessonList(lesson);
    }

    /**
     * 新增课程视频
     * 
     * @param lesson 课程视频
     * @return 结果
     */
    @Override
    public int insertLesson(Lesson lesson)
    {
        lesson.setCreateBy(SecurityUtils.getLoginUser().getUserId().toString());
        lesson.setCreateTime(DateUtils.getNowDate());
        if (StrUtil.isBlank(lesson.getCover())) {
            lesson.setCover(lesson.getUrl() + "?vframe/jpg/offset/1");
        }
        return lessonMapper.insertLesson(lesson);
    }

    /**
     * 修改课程视频
     * 
     * @param lesson 课程视频
     * @return 结果
     */
    @Override
    public int updateLesson(Lesson lesson)
    {
        lesson.setUpdateBy(SecurityUtils.getLoginUser().getUserId().toString());
        lesson.setUpdateTime(DateUtils.getNowDate());
        if (StrUtil.isBlank(lesson.getCover())) {
            lesson.setCover(lesson.getUrl() + "?vframe/jpg/offset/1");
        }
        return lessonMapper.updateLesson(lesson);
    }

    /**
     * 批量删除课程视频
     * 
     * @param ids 需要删除的课程视频主键
     * @return 结果
     */
    @Override
    public int deleteLessonByIds(Integer[] ids)
    {
        return lessonMapper.deleteLessonByIds(ids);
    }

    /**
     * 删除课程视频信息
     * 
     * @param id 课程视频主键
     * @return 结果
     */
    @Override
    public int deleteLessonById(Integer id)
    {
        return lessonMapper.deleteLessonById(id);
    }
}
